﻿#region
/*******************************************************************************
** File Name:		    TableInfoService.cs
** Creator:		        chao.jiang 
** EMail:               chao.jiang 
** Create date:	        
** Latest Modifier:
** Latest Modify date:
** Description:		    
** Modify History:
**
** Code Review:
**
** Version number:       1.0.0
*********************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using EWineShop.Service.Contracts;
using EWineShop.Service.Model;
using EWineShop.IBatisRepository;
using EWineShop.Respository;
using System.Data;
using EWineShop.Entity;

namespace EWineShop.Service
{
    public class TableInfoService : ITableInfoService
    {
		 ITableInfo tableInfo = new TableInfoRepository();
		 
		 #region  Auto Generation
		 

		public void UpdateByID (TableInfoModel model)
		{
			ETableInfo entity = ConvertModelToEntity(model);

            tableInfo.UpdateByID(entity);

		}

		public void DeleteByID (System.Int64 iD)
		{
		
            tableInfo.DeleteByID(iD);

		}
		 
        public TableInfoModel GetByID (System.Int64 iD)
        {
        
			ETableInfo entity = tableInfo.GetByID(iD);
			
            TableInfoModel model = ConvertEntityToModel(entity);


            return model;
        }
        
	
		public IList<TableInfoModel> GetAll ()
		{
			IList<ETableInfo> entity = tableInfo.GetAll();
			
			if (entity == null)
            {
                return null;
            }
            
            IList<TableInfoModel> list = new List<TableInfoModel>();

            foreach (var item in entity)
            {
                TableInfoModel model = ConvertEntityToModel(item);
                list.Add(model);
            }
            return list;   
			
		}
		
		private TableInfoModel ConvertEntityToModel(ETableInfo entity)
		{
			if (entity == null)
            {
                return null;
            }
			TableInfoModel model = new TableInfoModel();
                        model.ID = entity.ID;
                        model.Name = entity.Name;
                        model.Code = entity.Code;
                        model.TableTypeID = entity.TableTypeID;
                        model.TableAreaID = entity.TableAreaID;
                        model.Remark = entity.Remark;
                        model.CreateTime = entity.CreateTime;
                        model.UpdateTime = entity.UpdateTime;
                        return model;
		}
		
		private ETableInfo ConvertModelToEntity(TableInfoModel model)
		{
			if (model == null)
            {
                return null;
            }
			ETableInfo entity = new ETableInfo();
                        entity.ID = model.ID;
                        entity.Name = model.Name;
                        entity.Code = model.Code;
                        entity.TableTypeID = model.TableTypeID;
                        entity.TableAreaID = model.TableAreaID;
                        entity.Remark = model.Remark;
                        entity.CreateTime = model.CreateTime;
                        entity.UpdateTime = model.UpdateTime;
                        return entity;
		}
		
		
		
		#endregion
    }
}